﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
    /// <summary>
    /// UnitTest1 的摘要说明
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        #region 其他测试属性
        //
        // 您可以在编写测试时使用下列其他属性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前使用 TestInitialize 运行代码 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在运行每个测试之后使用 TestCleanup 运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [Ignore]
        public void TestMethod0()
        {
            MySHQ.DAL.MemberManager memberManager = new MySHQ.DAL.MemberManager();
            MySHQ.Model.Entities.TabMember member = new MySHQ.Model.Entities.TabMember();
            member.Address = "广州番禺";
            member.AreaId = 440100;
            member.Birthday = "1980-7-7";
            member.ContactTel = "020-84281000";
            member.Education = "本科";
            member.Email = "xingdavis@tom.com";
            member.Fax = "020-84281000";
            member.Homepage = "http://www.homepage.com";
            member.Honor = 0;
            member.Industry = "IT";
            member.MemberType = 1;
            member.Mobile = "13725238829";
            member.NickName = "davis";
            member.OpenLevel = 0;
            member.Password = "davis";
            member.Photo = "";
            member.Qq = "12345678";
            member.RegTime = DateTime.Now;
            member.Score = 0;
            member.Sex = 1;
            member.Signed = "";
            member.Status = 1;
            member.TrueName = "xingdavis";
            member.Uname = "xingdavis";
            int rtn = memberManager.Add(member);
            Assert.IsTrue(rtn > 0);
        }

        [Ignore]
        public void TestMethod1()
        {
            //
            // TODO: 在此添加测试	逻辑
            //
            MySHQ.DAL.ShopManager shopManager = new MySHQ.DAL.ShopManager();
            MySHQ.Model.Entities.TabShop shop = new MySHQ.Model.Entities.TabShop();
            shop.Address = "广州市天河区黄埔大道西广电大厦";
            shop.AreaCode = 440100;
            shop.ContactTel = "020-88404998";
            shop.Creator = 1;
            shop.HasPic = false;
            shop.Hits = 0;
            shop.Introduce = "无";
            shop.IsTop = 0;
            shop.Mobile = "13725238829";
            //shop.Price = 0.0;
            shop.PublicTime = DateTime.Now;
            shop.ShopName = "广东融讯科技";
            shop.Status = 0;
            shop.Tags = "IT 地图";
            shop.TypeId = 23020100;
            shop.UpdateTime = DateTime.Now;
            shop.WebUrl = "http://www.rocent.com";

            int rtn = shopManager.Add(shop);
            MySHQ.DAL.ShopExtManager shopExtManager = new MySHQ.DAL.ShopExtManager();
            MySHQ.Model.Entities.TabShopExt shopExt = new MySHQ.Model.Entities.TabShopExt();
            shopExt.BookInfo = 1;
            shopExt.BookRoom = 1;
            shopExt.Brands = "地图 POI";
            shopExt.BrushCard = 1;
            shopExt.DutyTime = 1;
            shopExt.NearBuilding = "省高院";
            shopExt.ParkInfo = 1;
            shopExt.Sid = rtn;
            shopExt.TabShopObj = shop;
            shopExt.TakeAway = 1;
            rtn = shopExtManager.Add(shopExt);
            Assert.IsTrue(rtn > 0);
        }

        [TestMethod]
        public void TestMethod2()
        {
            MySHQ.DAL.ShopManager shopManager = new MySHQ.DAL.ShopManager();
            MySHQ.Model.Entities.TabShop shop = shopManager.GetById(6);
            //Assert.IsNull(shop);
            Assert.IsNotNull(shop.TabShopExtObj);
        }

        [TestMethod]
        public void TestMethod3()
        {
            MySHQ.DAL.ShopExtManager shopExtManager = new MySHQ.DAL.ShopExtManager();
            MySHQ.Model.Entities.TabShopExt shopExt = shopExtManager.GetById(6);
            Assert.IsNotNull(shopExt.TabShopObj);
        }

        [Ignore]
        public void TestMethod4()
        {
            MySHQ.DAL.ShopManager shopMangager = new MySHQ.DAL.ShopManager();
            IList<MySHQ.Model.Entities.TabShop> shops = shopMangager.GetByKeyword("融", 440600, 0, 5,NHibernate.Criterion.Order.Asc("Sid"));
            //IList<MySHQ.Model.Entities.TabShop> shops = shopMangager.GetByKeyword("融", 440100, 0, 5);
            Assert.IsNotNull(shops);
        }

        [TestMethod]
        public void TestMethod5()
        {
            MySHQ.DAL.BaseManager<MySHQ.Model.Entities.TabShop> bm = new MySHQ.DAL.BaseManager<MySHQ.Model.Entities.TabShop>();
            NHibernate.Criterion.DetachedCriteria dc = NHibernate.Criterion.DetachedCriteria.For<MySHQ.Model.Entities.TabShop>();
            // if (AreaCode % 100 > 0)//指定某区
            //    ic.Add(NHibernate.Criterion.Restrictions.Eq("AreaCode", AreaCode));
            //else//全市所有区
            //{
            //    int lastArea = ((AreaCode + 100) / 100) * 100;
            //    ic.Add(NHibernate.Criterion.Restrictions.And(NHibernate.Criterion.Restrictions.Ge("AreaCode", AreaCode), NHibernate.Criterion.Restrictions.Lt("AreaCode", lastArea)));
            //}
            //ic.Add(NHibernate.Criterion.Restrictions.Or(NHibernate.Criterion.Restrictions.Like("ShopName", "%" + keyword + "%"), NHibernate.Criterion.Restrictions.Like("Tags", "%" + keyword + "%")));
            //total = Count(ic);
            //ic.SetFirstResult(startIndex);
            //ic.SetMaxResults(maxNum);
            string keyword = "融";
            dc.Add(NHibernate.Criterion.Restrictions.Eq("AreaCode", 440100));
            dc.Add(NHibernate.Criterion.Restrictions.Or(NHibernate.Criterion.Restrictions.Like("ShopName", "%" + keyword + "%"), NHibernate.Criterion.Restrictions.Like("Tags", "%" + keyword + "%")));
            IEnumerable<MySHQ.Model.Entities.TabShop> shops = bm.FindAll(dc, 0, 5, null);
            Assert.IsNotNull(shops);
        }

        [TestMethod]
        public void TestMethod6()
        {
            int AreaCode = 440100;
            int lastArea = ((AreaCode + 100) / 100) * 100;
            string keyword = "融";
            MySHQ.DAL.BaseManager<MySHQ.Model.Entities.TabShop> bm = new MySHQ.DAL.BaseManager<MySHQ.Model.Entities.TabShop>();
            NHibernate.Criterion.DetachedCriteria dc = NHibernate.Criterion.DetachedCriteria.For<MySHQ.Model.Entities.TabShop>();
            dc.Add(NHibernate.Criterion.Restrictions.And(NHibernate.Criterion.Restrictions.Ge("AreaCode", AreaCode), NHibernate.Criterion.Restrictions.Lt("AreaCode", lastArea)));
            dc.Add(NHibernate.Criterion.Restrictions.Or(NHibernate.Criterion.Restrictions.Like("ShopName", "%" + keyword + "%"), NHibernate.Criterion.Restrictions.Like("Tags", "%" + keyword + "%")));
            NHibernate.Criterion.Order order1 = new NHibernate.Criterion.Order("Sid", false);
            IEnumerable<MySHQ.Model.Entities.TabShop> shops = bm.FindAll(dc, 0, 5,order1);
            Assert.IsNotNull(shops);
        }
    }
}
